#include<bits/stdc++.h>
//#define int long long
using namespace std;
char buf[1<<23],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if(!x)
        putchar('0');
    char F[200];
    int tmp=x>0?x:-x;
    if(x<0)
        putchar('-');
    int cnt=0;
    while(tmp>0)
        F[cnt++]=tmp%10+'0',tmp/=10;
    while(cnt>0)
        putchar(F[--cnt]);
}
const int maxn=5e3+10,mod=998244353;
const int inf=1e9;
int a[maxn]dp[maxn][maxn],s[maxn][maxn];
int l[maxn],r[maxn];
signed main()
{
	freopen("after.in","r",stdin);
	freopen("after.out","w",stdout);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	dp[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		l[i]=i;
		while(l[i]>1&&a[l[i]-1]<=a[i])
			l[i]--;
		r[i]=i;
		while(r[i]<n&&a[r[i]+1]<=a[i])
			r[i]++;
	}
	for(int j=1;j<=n;j++)
		s[0][j]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(i>=l[j]&&i<=r[j])
				dp[i][j]=s[i-1][j];
			s[i][j]=(s[i][j-1]+dp[i][j])%mod;
		}		
	}
	cout<<s[n][n];
	putchar('\n');
	return 0;
}
